home *** CD-ROM | disk | FTP | other *** search
- #! /bin/awk -f
- #
- # RCSid[] = "@(#)$Header: simple.awk,v 3.0 86/09/26 10:13:31 pb Rel $"
- #
- # squash up the output from nrs into smaller form
- # for new-format york directory
- #
- BEGIN { FS = ":" ; isunix = "UNSET" }
- { # if it's ANOTHER VALID FIELD for the same place, add service
- if ( NF==8 && (isunix==$1 || isunix=="0" || $1=="0") && \
- network==$2 && name==$4 && (addr==$5 || addr=="" || $5=="") && \
- strip==$6)
- {
- # we ought to do ``isunix |= $1'', but not in awk we can't
- # SO: approximate: We know ((x | 0) == x) ......
- if (isunix=="0") isunix = $1;
-
- if ( split($3, ar, "|") == 1)
- revservice = revservice ar[1];
- else revservice = revservice ar[2];
- service = service ar[1];
-
- if (addr == "") addr = $5;
-
- if ($7 != "")
- { if (values == "") values = $7;
- else values = values "|" $7;
- }
-
- if ($8 != "")
- { text = text "|" $8;
- n = split(text, ar, "|");
- for (i=1; i<n; i++)
- for (j=i+1; j<=n; j++)
- if (ar[i] == ar[j]) ar[j] = "";
- text = ""
- for (i=1; i<=n; i++) if (ar[i] != "")
- { if (text == "") text = ar[i];
- else text = text "|" ar[i];
- }
- }
- }
- else # First write out pending (if any)
- { if (isunix != "UNSET")
- {
- if (service ~ /t/ && service ~ /f/ && service ~ /m/)
- { split(service, ar, "t"); service = ""
- for (elem in ar) service = service ar[elem]
- split(service, ar, "f"); service = ""
- for (elem in ar) service = service ar[elem]
- split(service, ar, "m"); service = ""
- for (elem in ar) service = service ar[elem]
- service = "Y" service
- }
- if (service ~ /Y/ && service ~ /x/)
- { split(service, ar, "Y"); service = ""
- for (elem in ar) service = service ar[elem]
- split(service, ar, "x"); service = ""
- for (elem in ar) service = service ar[elem]
- service = "X" service
- }
-
- if (revservice ~ /t/ && revservice ~ /f/ && revservice ~ /m/)
- { split(revservice, ar, "t"); revservice = ""
- for (elem in ar) revservice = revservice ar[elem]
- split(revservice, ar, "f"); revservice = ""
- for (elem in ar) revservice = revservice ar[elem]
- split(revservice, ar, "m"); revservice = ""
- for (elem in ar) revservice = revservice ar[elem]
- revservice = "Y" revservice
- }
- if (revservice ~ /Y/ && revservice ~ /x/)
- { split(revservice, ar, "Y"); revservice = ""
- for (elem in ar) revservice = revservice ar[elem]
- split(revservice, ar, "x"); revservice = ""
- for (elem in ar) revservice = revservice ar[elem]
- revservice = "X" revservice
- }
- # If identical, then merge ....
- if ( service != revservice )
- service = service "|" revservice;
- print isunix":"network":"service":"name":"addr":"strip":"values":"text
- }
- if (NF == 8) # if valid, save the info
- { isunix = $1; network = $2
- name = $4; addr = $5 "";
- strip = $6; values = $7; text = $8
- if ( split($3, ar, "|") == 1)
- revservice = ar[1];
- else revservice = ar[2];
- service = ar[1];
- }
- else # invalid: just print it asis
- { print $0; isunix = "UNSET"
- }
- }
- }
- END { if ( isunix != "UNSET" ) # Flush any pending data
- print isunix":"network":"service"|"revservice":"name":"addr":"strip":"values":"text
- }
-